class DebugLogging {
    constructor() {
        this.init();
    }

    init() {
        this['takeUpTime'];
        this['nodeId'];
        this['nodeType'];
        this['nodeName'];
        this['nodeInput'] = {};
        this['nodeOutput'] = {};
        this['nodeDebug'] = [];
        this['timestamp'] = DebugLogging.getTimestamp();
        this['status'] = 'SUCCESS';
        this['throwable'];
    }

    assignParam(nodeId, nodeType, nodeName, input, output, logStartTime, logEndTime) {
        this['takeUpTime'] = (logEndTime - logStartTime) + 'ms';
        this['nodeId'] = nodeId;
        this['nodeType'] = nodeType;
        this['nodeName'] = nodeName;
        this['nodeInput'] = input;
        this['nodeOutput'] = output
    }

    assignCommParam(nodeId, nodeType, nodeName, input, output) {
        this['nodeId'] = nodeId;
        this['nodeType'] = nodeType;
        this['nodeName'] = nodeName;
        this['nodeInput'] = input;
        this['nodeOutput'] = output;
    }

    assignCommNoOutputParam(nodeId, nodeType, nodeName, input, logStartTime, logEndTime) {
        this['takeUpTime'] = (logEndTime - logStartTime) + 'ms';
        this['nodeId'] = nodeId;
        this['nodeType'] = nodeType;
        this['nodeName'] = nodeName;
        this['nodeInput'] = input
    }

    assignWithoutInputAndOutputParam(nodeId, nodeType, nodeName, logStartTime, logEndTime) {
        this['takeUpTime'] = (logEndTime - logStartTime) + 'ms';
        this['nodeId'] = nodeId;
        this['nodeType'] = nodeType;
        this['nodeName'] = nodeName;
    }

    pushDebug(deb) {
        this['nodeDebug'].push(deb);
    }

    static getTimestamp() {
        return Date.now();
    }

    assignInput(input) {
        this['nodeInput'] = input;
    }

    assignNodeId(nodeId) {
        this['nodeId'] = nodeId;
    }

    assignNodeType(nodeType) {
        this['nodeType'] = nodeType;
    }

    assignNodeName(nodeName) {
        this['nodeName'] = nodeName;
    }

    assignOutput(output) {
        this['nodeOutput'] = output;
    }

    assignDiffTime(logStartTime, logEndTime) {
        this['takeUpTime'] = (logEndTime - logStartTime) + 'ms';
    }

    assignThrowable(throwable) {
        this['status'] = 'ERROR';
        this['throwable'] = throwable;
    }
}

class JsonResult {
    constructor() {
        this.init();
    }

    init() {
        this.code = 0;
        this.data = null;
        this.msg = 'success';
        this.debugLog = [];
    }

    setCode(code) {
        this.code = code
    }

    setMsg(msg) {
        this.msg = msg
    }

    setData(data) {
        this.data = data
    }
}

class TraceInfo {
    constructor(eventName, traceId) {
        this['eventName'] = eventName;
        this['traceId'] = traceId;
        this['time'] = this.getTime();
        this['bindIds'] = new Array();
    }

    getTime() {
        let date = new Date();
        let y = date.getFullYear(), m = date.getMonth() + 1, d = date.getDate();
        return '' + y + '-' + (m < 10 && ('0' + m) || m) + '-' + (d < 10 && ('0' + d) || d);
    }

    pushBindId(bindId) {
        this['bindIds'].push(bindId);
    }
}

module.exports = {DebugLogging, JsonResult, TraceInfo}